package com.itheima.search.web;
import com.hmall.common.dto.PageDTO;
import com.hmall.common.pojo.Item;
import com.itheima.search.pojo.ItemDoc;
import com.itheima.search.pojo.RequestParams;
import com.itheima.search.service.SearService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RequestMapping("/search")
@RestController
public class SearchController {

    @Autowired
    private SearService service;

    @GetMapping("/suggestion")
    public List<String> suggestion(@RequestParam("key") String prefix){
        return service.getSuggestions(prefix);
    }

    @PostMapping("filters")
    public Map<String, List<String>> getFilters(@RequestBody RequestParams params) {
        return service.getFilers(params);
    }

    @PostMapping("list")
        public PageDTO<ItemDoc> search(@RequestBody RequestParams params) {
        return service.search(params);
    }


}
